package com.hpeng.sys.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.hpeng.sys.dao.AssetCardBooksDao;
import com.hpeng.sys.model.AssetCard;
import com.hpeng.sys.model.AssetCardBook;
import com.hpeng.util.GenericDaoImpl;
@Component("assetCardBooksDao")  
public class AssetCardBookDaoImpl extends GenericDaoImpl<AssetCardBook,String> implements AssetCardBooksDao{
	public List<AssetCardBook> getByAcprimarystatus(){
		List<AssetCardBook> assetCardBook = null;
		assetCardBook = getByHql("from AssetCardBook assetCardBook where assetCardBook.acprimarystatus = '1' order by assetCardBook.acprimarystatus.operatedate");
		for(int i = 0;i< assetCardBook.size();i++){
			System.out.println(assetCardBook.get(i).getAcbid());
		}
		return assetCardBook;
	}
	public List<AssetCardBook> getByAcprimarystatusToStatus(){
		List<AssetCardBook> assetCardBook = null;
		assetCardBook = getByHql("from AssetCardBook assetCardBook where assetCardBook.acprimarystatus = '3' order by assetCardBook.acprimarystatus.operatedate");
		for(int i = 0;i< assetCardBook.size();i++){
			System.out.println(assetCardBook.get(i).getAcbid());
		}
		return assetCardBook;
	}
	public List<AssetCardBook> getByAcprimarystatusToOver(){
		List<AssetCardBook> assetCardBook = null;
		assetCardBook = getByHql("from AssetCardBook assetCardBook where assetCardBook.acprimarystatus = '6' order by assetCardBook.acprimarystatus.operatedate");
		for(int i = 0;i< assetCardBook.size();i++){
			if(assetCardBook.get(i).getCard()!=null){
				System.out.println(assetCardBook.get(i).getCard().getAcid());
			}else{
				System.out.println("卧槽");
			}
		}
		return assetCardBook;
	}
	public List<AssetCardBook> getByAssetCardList(List<AssetCard> assetCards){
		List<AssetCardBook> assetCardBooks = new ArrayList<AssetCardBook>();
		List<AssetCardBook> assetCardBook = null;
		for(int i =0;i<assetCards.size();i++){
		assetCardBook = getByHql("from AssetCardBook assetCardBook where rownum = 1 and assetCardBook.card='"+assetCards.get(i).getAcid()+"' order by assetCardBook.operatedate desc");
			if(assetCardBook.size()>0){
				assetCardBooks.add(assetCardBook.get(0));
			}
		}
		System.out.println(assetCardBooks);
		return assetCardBooks;
	}
	public boolean add(AssetCardBook assetCardBook){
		save(assetCardBook);
		return true;
	}
}
